﻿namespace Sai.Core.Reporting
{
	public class EmbeddedResourceTransformation : IReportTransformation
	{
        private ITextTransformer _transformer;

        public EmbeddedResourceTransformation(string styleSheetName)
        {
            this.StyleSheetName = styleSheetName;
        }

        private string StyleSheetName { get; set; }

        private ITextTransformer Transformer
        {
            get
            {
                if (this._transformer == null)
                {
                    XmlTransformerFactory factory = new XmlTransformerFactory();

                    this._transformer = factory.CreateFromResource(this.StyleSheetName);
                }

                return this._transformer;
            }
        }

		public string Transform(IFlattenToXml difference)
		{
            return this.Transformer.Transform(difference.ToXml());
		}
	}
}
